<?php echo $this->title($this->pageTitle) ?>

<?php if (!$this->productId) :
    echo $this->translate('catalog')->__('Product not found');
    return;
    endif;?>

<?php if (count($this->data['reviews'])):
$review = current($this->data['reviews']);
$productUrl = $this->hurl(array(
    'product' => array('value' => $review['product_id'], 'seo' => $review['product_key_word']),
    'controller' => 'catalog',
    'action' => 'product'
), false, true);
?>

<div class="review-product-average">
    <div class="head">
        <h2><a href="<?php echo $productUrl ?>"
            class="product-name"
            title="<?php echo $this->translate('community')->__("Read about %s", $review['product_name']) ?>"
        ><?php echo $review['product_name'] ?></a></h2>
    </div>
    <div class="content">
        <div class="product-image">
            <a href="<?php echo $productUrl;?>" 
                title="<?php echo $this->escape($review['product_image_title']) ?>"
            ><?php
                echo $this->imager('/product' . $review['product_image_thumbnail'], array(
                    'width'  => $this->config()->image->product->widthSmall,
                    'height' => $this->config()->image->product->heightSmall,
                    'alt' => $this->escape($review['product_image_title']),
                    'seo' => $review['product_image_seo_name']
                ));
            ?></a>
        </div>
        <div class="product-info">
            <?php if (isset($this->average_ratings[$this->productId])): ?>
                <?php echo $this->ratings($this->average_ratings[$this->productId], '#', false) ?>
            <?php else: ?>
                <?php echo $this->translate('community')->__('No ratings are available') ?>
            <?php endif; ?>
        </div>
        <div class="product-common">
            <?php echo $this->price($review['product_price'], 
                !empty($review['product_price_discount']) ? 
                    $review['product_price_discount'] : false
            ) ?>
            <?php if (Ecart::single('community/review')->canAdd()) : ?>
            <a href="#form-review"
                rel="nofollow"
                title="<?php echo $this->translate('community')->__("Write review for %s", $review['product_name']) ?>"
            ><span><?php echo $this->translate('community')->__("Write review") ?></span></a>
            <?php else: ?>
            <a href="<?php echo $this->href('review/login') ?>"
                rel="nofollow"
                title="<?php echo $this->translate('community')->__("Log in to write a review") ?>"
            ><span><?php echo $this->translate('community')->__("Log in to write a review") ?></span></a>
            <?php endif ?>
        </div>
    </div>
</div>

<?php echo $this->render('review/list/toolbar.phtml') ?>
<ol class="review-product-list">
<?php foreach ($this->data['reviews'] as $review) : 

if (empty($review['customer_id'])):
    $author = empty($review['author']) ? 'Guest' : $review['author'];
else:
    $authorUrl = $this->href("review/customer/id/{$review['customer_id']}");
    $authorTitle = $this->translate('community')->__("View all reviews written by %s", $review['author']);
    $author = "<a href='" . $authorUrl . "' title='" . $authorTitle . "' class='review-author'>{$review['author']}</a>";
endif;

?>
<li class="review" id="review_<?php echo $review['id'] ?>">
    <div class="review-info">
        <h5 class="review-title"><a href="<?php echo $this->href("review/detail/id/{$review['id']}") ?>" title="Read review"><?php echo $review['title'] ?></a></h5>
        <span class="review-date"><small><?php echo $this->translate('community')->__("Reviewed on %s by %s", $review['date_created'], $author) ?></small></span>
        <p class="review-pros"><strong><?php echo $this->translate('community')->__("Pros") ?>: </strong><?php echo $this->escape($review['pros']) ?></p>
        <p class="review-cons"><strong><?php echo $this->translate('community')->__("Cons") ?>: </strong><?php echo $this->escape($review['cons']) ?></p>
        <p class="review-summary"><strong><?php echo $this->translate('community')->__("Summary") ?>: </strong><?php echo $this->escape($review['summary']) ?></p>
    </div>
    <?php if (isset($review['ratings'])): ?>
        <?php echo $this->ratings($review['ratings'], $this->href("review/detail/id/{$review['id']}"), false) ?>
    <?php endif ?>
</li>
<?php endforeach; ?>
</ol>
<?php echo $this->render('review/list/toolbar.phtml') ?>
<?php else: 
    echo $this->translate('community')->__('There are no reviews for this product yet');
endif;?>

<div class="review-write">
    <div class="head"><h4 class="title"><?php echo $this->translate('community')->__("Write your review") ?></h4></div>
    <div class="content">
        <?php $this->headScript()->appendFile('/js/ecart/community/ratings.js') ?>
        <?php echo $this->formReview->render($this) ?>
        <?php if (!Ecart::single('community/review')->canAdd()) : ?>
        <a href="<?php echo $this->href('review/login') ?>"
            rel="nofollow"
            title="<?php echo $this->translate('community')->__("Log in to write a review") ?>"
        ><span><?php echo $this->translate('community')->__("Log in to write a review") ?></span></a>
        <?php endif ?>
        <script type="text/javascript">
            $("#form-review").validate();
            $('#form-review .review-rating').ratings();
        </script>
    </div>
</div>